#include "Application.h"
Application::Application(int width, int height, const char* name)
{
	m_pWindow = std::make_unique<Window>(width,height,name);
	auto wndHandle = m_pWindow->GetWindowHandle();
	m_pGfx = std::make_unique<Graphics>(wndHandle,width,height);
	sampleList = new SamplesList(*m_pGfx);
	timer.Reset();


}

int Application::Run()
{
	while (true)
	{
		if (const auto ecode = Window::ProcessMessages())
		{
			return *ecode;
		}
		timer.Tick();
		const auto dt = timer.DeltaTime();
		HandleInput(dt);
		Update(timer.TotalTime());
		Render(dt);
	}
}


void Application::GUI()
{
	sampleList->GUI();
	m_pWindow->SetTitle("TotalTime : "+std::to_string(timer.TotalTime()));
}

void Application::Render(float dt)
{
	const float color[4] = {0.0,0.0,0.0,1.0};
	m_pGfx->ClearBuffer(color);
	m_pGfx->BeginFrame();
	sampleList->Render(dt);
	GUI();
	m_pGfx->EndFrame();
}

void Application::HandleInput(float dt)
{
	
}

void Application::Update(float dt)
{
	sampleList->Update(dt);
}

